package cn.itchao.example.member.service;

import cn.itchao.example.goods.api.GoodsServiceApi;
import cn.itchao.example.goods.domain.Goods;
import cn.itchao.example.member.dao.MemberMapper;
import cn.itchao.example.member.domain.Member;
import cn.itchao.example.member.rest.GoodsDubboRestService;
import cn.itchao.example.member.rest.GoodsRestService;
import cn.itchao.exmaple.base.ApiResponse;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class MemberService {

    @Autowired
    private MemberMapper memberMapper;

    @Reference(protocol = "dubbo",check = false,timeout = 10000)
    private GoodsServiceApi goodsServiceApi;

    @Autowired
    @Lazy
    private GoodsRestService goodsRestService;

    @Autowired
    @Lazy
    private GoodsDubboRestService goodsDubboRestService;

    public Member queryMemberById(Long id){
//        return memberMapper.selectById(id);
        Member member = new Member();
        member.setId(id);
        member.setNickName("北岩");
        member.setEmail("370696614@qq.com");
        return member;
    }


    public Goods findGoodsById(Long id){
        ApiResponse<Goods> apiResponse = goodsServiceApi.findGoodsById(id);
        if(apiResponse.getCode()==200){
            Goods data = apiResponse.getData();
            return data;
        }
        return null;
    }

    public Goods findGoodsRestById(Long id){
        ApiResponse<Goods> apiResponse = goodsRestService.findGoodsById(id);
        if(apiResponse.getCode()==200){
            Goods data = apiResponse.getData();
            return data;
        }
        return null;
    }

    public Goods findGoodsDubboRestById(Long id){
        ApiResponse<Goods> apiResponse = goodsDubboRestService.findGoodsById(id);
        if(apiResponse.getCode()==200){
            Goods data = apiResponse.getData();
            return data;
        }
        return null;
    }
}
